package com.example.basic.demos.exception;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 处理业务异常
     *
     */
    @ExceptionHandler(value = BusinessException.class)
    @ResponseBody
    public String businessExceptionHandler(BusinessException e) {
        return e.getMsg();
    }

    /**
     * 处理其它异常
     */

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public String exceptionHandler(Exception e) {
        return e.getMessage();
    }
}
